package cn.yudao.controller;

import cn.yudao.block.UserBlockHandler;
import cn.yudao.entity.User;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class UserController {

    @Value("${test}")
    private Long test;


    @GetMapping("/getuser/{id}")
    @SentinelResource(value = "getUserByid",
            blockHandler = "getUserByidBlockHandler",
            blockHandlerClass = UserBlockHandler.class,
            fallback = "getUserByidFallback")
    public User getUserByid(@PathVariable Long id){
        System.out.println(1/0);
        return User.builder().age(8L).id(id).name("王刚").intro("是贾思涵儿子").build();
    }

    public static User getUserByidFallback(@PathVariable Long id){
        return User.builder().age(80L).id(-2L).name("fallback").intro("getUserByidFallback").build();
    }

}
